// pages/goods_list/goods_list.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.paramid = options.id;
    this.goods_type = options.goods_type || 0;  //0表示分类商品，1表示分组商品
    this.getGoodsOption();

    //获取我的用户信息
    this.getMyInfo();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    var path = '/pages/homepage/homepage';
    return {
      title: '【' + this.myinfo.user_name + '】，该商品用星星减免超级优惠，全场包邮>>',
      path: path,
      success: () => {
      }
    }
  },

  /**
   * 获取我的用户信息
   */
  getMyInfo: function () {
    app.getUserInfo((res) => {
      this.myinfo = res
    })
  },

  /**
   * 三级分类商品
   */
  getGoodsOption: function() {
    var goodsOption;
    var showType;
    if (this.goods_type == 1) {
      var goodsOption = {
        list_id: 'free_son_goods',
        url: '/api/index.php?app=category&act=group_goods',
        data: {
          group_id: this.paramid
        }
      }
      showType = 'exchange';
    } else {
      var goodsOption = {
        list_id: 'third_goods',
        url: '/api/index.php?app=category&act=category_goods',
        data: {
          gtid: this.paramid
        }
      }
      showType = 'play';
    }
    this.setData({
      showType: showType,
      goodsOption: goodsOption,
      pageHeight: app.globalData.pageHeight,
    })
  },

  /**
   * 加载更多商品
   */
  loadMoreGoods: function(e) {
    this.setData({
      goodsList: e.detail.data,
    })
  },

  /**
   * 查看商品详情 
   */
  lookGoodsInfo: function(e) {
    var id = e.detail.id;
    if (this.goods_type == 0) {
      wx.navigateTo({
        url: '../../goods_detail/goods_detail?goods_id=' + id,
      })
    } else if (this.goods_type == 1) {
      wx.navigateTo({
        url: '../../goods_detail/goods_detail?group_id=' + this.paramid +'&goods_id=' + id,
      })
    }
  }

})